/**
 * 
 */
package org.wattdepot.cli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the ListPowerForDay class.
 * 
 * @author George Lee
 *
 */
public class TestPowerStatsCommand extends CommandTestBed {

  /** 
   * Tests the doCommand method of ListPowerForDayCommand.
   * 
   * @see org.wattdepot.cli.command.CommandTestBed#testDoCommand()
   */
  @Test
  @Override
  public void testDoCommand() {
    String command, result;
    
    PowerStatsCommand listCommand = new PowerStatsCommand(this.client);
    
    // Sad tests
    command = "powerstats foo SIM_KAHE day 2009-11-01 sampling-interval 60 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the command is invalid.", 
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));

    command = "powerstats consumed SIM_KAHE foo 2009-11-01 sampling-interval 60 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the day parameter is incorrect.",
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));

    command = "powerstats consumed SIM_KAHE day foo sampling-interval 60 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the timestamp result is invalid.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));

    command = "powerstats consumed SIM_KAHE day 2009-11-01 foo 60 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the interval parameter is incorrect.",
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));
    
    command = "powerstats consumed SIM_KAHE day 2009-11-01 sampling-interval -1 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the sampling interval is invalid.",
        result.startsWith(WattDepotCliCommand.INTERVAL_ERROR));
    
    command = "powerstats consumed SIM_KAHE day 2009-11-01 sampling-interval 60 foo max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the statistic parameter is incorrect.",
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));
    
    command = "powerstats consumed SIM_KAHE day 2009-11-01 sampling-interval 60 statistic foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that statistic parameter is invalid",
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));
    
    // Happy tests
    command = "powerstats generated SIM_KAHE day 2009-11-01 sampling-interval 120 statistic max";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a result from the max operation.", 
        Double.valueOf(result) >= 0);
    assertFalse("Checking that the command is valid.", 
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the day parameter is correct.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the timestamp result is valid.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    assertFalse("Checking that the interval parameter is correct.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the sampling interval is correct.",
        result.startsWith(WattDepotCliCommand.INTERVAL_ERROR));
    assertFalse("Checking that the statistic parameter is incorrect.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that statistic parameter is valid",
        "Invalid statistic type foo".equals(result));
    
    command = "powerstats generated SIM_KAHE day 2009-11-15 sampling-interval 120 statistic min";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a result from the min operation.", 
        Double.valueOf(result) >= 0);
    
    command = "powerstats consumed SIM_OAHU_GRID day 2009-11-02"
                          + " sampling-interval 120 statistic average";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a result from the average operation.", 
        Double.valueOf(result) >= 0);
  }

}
